import { _decorator, Component, Node } from 'cc';
import { Core } from './Core/Core';
import { EEvent, EGameMode, EPlayerType } from './Config/Enum';
const { ccclass, property } = _decorator;

@ccclass('PlayerListItem')
export class PlayerListItem extends Component {
    ndReddot: Node = null;  
    msg


    protected onLoad(): void {
        //this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.ndReddot = this.node.getChildByName("reddot");
        
    }

    protected onEnable(): void {
        this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
    }

    protected onDisable(): void {
        // 清理事件监听
        this.node.off(Node.EventType.TOUCH_START, this.onTouchStart, this);
        
    }


    start() {
        //


    }

    update(deltaTime: number) {
        
    }


    showReddot(){
        this.ndReddot.active = true;
    }


    onTouchStart(){
        // 处理触摸开始事件

        // 判断有没有解锁m，如果有解锁
        if (Core.Instance.unlockedPlayers.indexOf(this.node.name as EPlayerType)!== -1) {
            Core.Instance.currentPlayer = this.node.name as EPlayerType;
            Core.Instance.event.emit(EEvent.PlayerDataUpdated);
        } else {
            //console.log("当前玩家未解锁", this.node.name);



            let currentStage = Core.Instance.modeMaxStage[EGameMode.Normal];
            //console.log("当前游戏模式", EGameMode.Normal, "当前关隘", currentStage);
            if(currentStage < 3){
                this.msg = "通过襄阳烽烟第 3 关招募下一位义士";   
            }
            if(currentStage >= 3 && currentStage < 7){
                this.msg = "通过襄阳烽烟第 7 关招募下一位义士";   
            }
            if(currentStage >= 7 && currentStage < 13){
                this.msg = "通过襄阳烽烟第 13 关招募下一位义士";   
            }
            if(currentStage >= 13 && currentStage < 19){
                this.msg = "通过襄阳烽烟第 19 关招募下一位义士";   
            }
            if(currentStage >= 19 && currentStage < 25){
                this.msg = "通过襄阳烽烟第 25 关招募下一位义士";   
            }



            // 显示Tips
            Core.Instance.showTips(this.msg);
            





            //Core.Instance.event.emit(EEvent.PlayerNotUnlocked, this.node.name);
        }
    }
}


